import 'package:flutter/material.dart';
import 'package:geomancy/enums/index.dart';
import 'package:geomancy/providers/gallery_provider.dart';
import 'package:geomancy/widgets/gallery_util/components/crop_photo.dart';
import 'package:geomancy/widgets/modal_util/index.dart';
import 'package:go_router/go_router.dart';
import 'package:photo_manager/photo_manager.dart';
import 'package:photo_manager_image_provider/photo_manager_image_provider.dart';
import 'package:provider/provider.dart';

class AssetsEntityWidget extends StatelessWidget {
  final AssetEntity entity;
  final Size size;
  final double radius;
  final bool isChecked;//是否选中
  final int? currentIndex;
  final bool? showCheckbox;
  const AssetsEntityWidget({super.key, required this.entity, required this.size, this.radius = 0, this.isChecked = false, this.currentIndex, this.showCheckbox});

  @override
  Widget build(BuildContext context) {
    final scene = context.read<GalleryProvider>().getGalleryScene;
    return GestureDetector(
      onTap: () {
        switch(scene) {
          case GalleryScene.avatar:
          case GalleryScene.registerAvatar:
            ModalUtil.showGeneralDialogWidget(
                context: context,
                modalWidget: CropAvatarPage(entity: entity)
            );
            break;
          default:
            context.push('/view_media', extra: {
              "entity": entity
            });
            break;
        }
      },
      child: ClipRRect(
        borderRadius: BorderRadius.all(Radius.circular(radius)),
        child: SizedBox(
          width: size.width,
          height: size.height,
          child: Stack(
            children: [
              Positioned.fill(child: AssetEntityImage(
                entity,
                isOriginal: false,
                thumbnailSize: ThumbnailSize.square((size.width * 2).toInt()),
                fit: BoxFit.cover,
              )),
              ///勾选圈(默认场景下才会显示)
              // if ((scene == GalleryScene.common || scene == GalleryScene.feedback)
              //     && showCheckbox != false)
              //   Positioned(
              //     top: 0,
              //     right: 0,
              //     child: GestureDetector(
              //       onTap: () {
              //         // eventListener.emit(Constant.GALLERYCIRCLETAP, entity);
              //       },
              //       child: Container(
              //         padding: EdgeInsets.fromLTRB(8.w, 2.w, 2.w, 8.w),
              //         color: Colors.transparent,
              //         child: SizedBox(
              //           width: 20.w,
              //           height: 20.w,
              //           child: Stack(
              //             children: [
              //               isChecked ? Image.asset('assets/icons/icon_gallery_circle_selected.png', width: 20.w) : Image.asset('assets/icons/icon_gallery_circle.png', width: 20.w),
              //               if (currentIndex != null && currentIndex! >= 0)
              //                 Align(child: Text(currentIndex.toString(), style: TextStyle(fontSize: 11.sp, color: Colors.white)))
              //             ],
              //           ),
              //         ),
              //       ),
              //     ),
              //   ),
            ],
          ),
        ),
      ),
    );
  }
}
